<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%>
<%@ include file="/common/backcommon.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Breaking Fast</title>
		<script type="text/javascript">
			function deleteOperate(id) {
				if(confirm("是否删除该周菜单？")) {
					$.ajax({
						url: "${base}/backWeekMenuCtl/delete",
						type: "post",
						data: {weekMenuId : id},
						success: function(result){
							if(true == result) {
								alert("删除成功");
							}
						},
						error:function(){
							alert("删除失败");
						}
					});
					setTimeout("onPageChange(1)", 2000);
				}
			};
			
			function updateOperate(id) {
				location.href = "${base}/backWeekMenuCtl/toUpdate?weekMenuId=" + id;
			};
			
			function detailOperate(id) {
				location.href = "${base}/backWeekMenuCtl/detail?weekMenuId=" + id;
			};
			
	        function loadPage(totalCount, pageSize, pageCurrent) {
		        $("#page").smartpaginator({
                    totalrecords: totalCount, 
                    recordsperpage: pageSize, 
                    initval: pageCurrent,  
                    next: '下一页', 
                    prev: '上一页', 
                    first: '第一页', 
                    last: '最后一页', 
                    theme: 'black', 
                    go: 'Go',
                    onchange: onPageChange
				});
	        };
			
			function onPageChange(newPageValue) {
				//获取查询参数
				var startDate = $("#startDate").val();
				var endDate = $("#endDate").val();
				var params = {
					startDate : startDate,
					endDate : endDate,
					pageNumber : newPageValue
				};
				var dataTr = $("#pageList tr");
				for(var i = 0; i < dataTr.length; i++) {
					if(i != 0) {
						$(dataTr[i]).remove();
					}
				}
				$.ajax({
					url: "${base}/backWeekMenuCtl/select",
					type: "post",
					data: params,
					success: function(result){
						var dataTable = $("#pageList");
						for(var i = 0; i < result.resultList.length; i++) {
							var trClassName = ""; 
							if(i%2 == 0){
								trClassName = "list_tab_left";
							}
							var weekmenuid = result.resultList[i].weekmenuid;
							var sellweek = result.resultList[i].sellweekStr;
							var price = result.resultList[i].price;
							var createdate = result.resultList[i].createdateStr;
							var username = result.resultList[i].createuser.username;
							var row = $("<tr class='" + trClassName + "'><td>" + sellweek + "</td><td>" + price + "</td><td>" + createdate + "</td><td>" + username + "</td>" + 
								"<td><a href='#' onclick='deleteOperate(\"" + weekmenuid + "\")'>删除</a>&nbsp;&nbsp;" + 
								"<a href='#' onclick='updateOperate(\"" + weekmenuid + "\")'>修改</a>&nbsp;&nbsp;" + 
								"<a href='#' onclick='detailOperate(\"" + weekmenuid + "\")'>详情</a></td></tr>");
							dataTable.append(row);
						}
						$("#pageList tr:even").addClass("bg_color");
						loadPage(result.totalCount, result.pageSize, result.pageCurrent);
					}
				});
			};
			
			$(function() {
				onPageChange(1);
				
				$("#queryBtn").bind("click",function(){
					if($.formValidator.pageIsValid("1")) {
						var pageNumber = $("#pageNumber").val();
						onPageChange(pageNumber);
					}
				});
				
				//验证信息
				$.formValidator.initConfig({
					formID: "queryForm",
					debug:false,
					onError: function(msg, obj, errorlist){
					}
				});
			});
		</script>
	</head>
	
	<body>
		<div class="cms_right">
		  	<div class="cms_title">
		    	<span>周菜单管理：</span>
		    </div>
			    <div class="cms_search">
	    			<form id="queryForm" >
						<table width="1000" border="0" class="search_bd">
							<tr>
								<td class="yh_name">开始时间：</td>
								<td class="yh_bd"><input type="text" id="startDate" class="Wdate" style="cursor: pointer" onFocus="WdatePicker({readOnly:true,isShowWeek:true,disabledDays:[2,3,4,5,6,0]})"/></td>
								<td class="tishi"><div id="startDateTip" style="width:200px"></div></td>
								<td class="yh_name">结束时间：</td>
								<td class="yh_bd"><input type="text" id="endDate" class="Wdate" style="cursor: pointer" onFocus="WdatePicker({readOnly:true,isShowWeek:true,disabledDays:[2,3,4,5,6,0]})"/></td>
								<td><div id="endDateTip" style="width:200px"></div></td>
							</tr>
							<tr>
								<td></td>
								<td align="right"><input type="reset" class="search_btn" value="重置" /></td>
								<td align="center" ><input type="button" id="queryBtn" class="search_btn" value="搜索" /></td>
								<td><input type="button" id="queryBtn" class="search_btn" value="新增" onclick="location.href='${base }/background/weekmenu/weekmenuadd.jsp'" /></td>
								<td></td>
								<td></td>
							</tr>
				        </table>
		   			</form>
			    </div>
			<div class="grid-view">
				<table id="pageList" class="items" width="100%" border="1" cellspacing="0" cellpadding="0">
					<tr class="list_tab_title">
						<td bgcolor="#eae9eb">销售日期(起始日)</td>
						<td bgcolor="#eae9eb">价格</td>
						<td bgcolor="#eae9eb">创建时间</td>
						<td bgcolor="#eae9eb">创建人</td>
						<td bgcolor="#eae9eb">操作</td>
					</tr>
				</table>
				<div id="page" style="margin: auto;"></div>
			</div>
		</div>
	</body>
</html>
	